package com.emeraldparser.collect;

public final class ImmutableEdge<V, E> extends AbstractEdge<V, E> {

	private final V source;
	private final V destination;
	private final E label;

	public ImmutableEdge(V source, V destination, E label) {
		this.source = source;
		this.destination = destination;
		this.label = label;
	}

	public static <V, E> ImmutableEdge<V, E> create(V source, V destination, E label) {
		return new ImmutableEdge<V, E>(source, destination, label);
	}

	@Override
	public V getSource() {
		return source;
	}

	@Override
	public V getDestination() {
		return destination;
	}

	@Override
	public E getLabel() {
		return label;
	}

	public static <V> BuilderWithSource<V> from(V source) {
		return new BuilderWithSource<V>(source);
	}

	public static final class BuilderWithSource<V> {

		private final V source;

		private BuilderWithSource(V source) {
			this.source = source;
		}

		public BuilderWithSourceAndDestination<V> to(V destination) {
			return new BuilderWithSourceAndDestination<V>(source, destination);
		}

	}

	public static final class BuilderWithSourceAndDestination<V> {

		private final V source;
		private final V destination;

		private BuilderWithSourceAndDestination(V source, V destination) {
			this.source = source;
			this.destination = destination;
		}

		public <E> ImmutableEdge<V, E> labelled(E label) {
			return new ImmutableEdge<V, E>(source, destination, label);
		}

	}

}
